//
//  BtnJumpViewController.m
//  LNA
//
//  Created by dllo on 16/1/19.
//  Copyright © 2016年 www.lanou3g.com蓝鸥. All rights reserved.
//

#import "BtnJumpViewController.h"
#import <AFNetworking.h>
#import "BtnJumpCell.h"
#import "BtnJumpModel.h"
#import <UIImageView+WebCache.h>
#import "CellJumpViewController.h"
@interface BtnJumpViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic, retain) UITableView *tableView;
@property (nonatomic, retain) NSMutableArray *dataArr;

@end

@implementation BtnJumpViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.tableView = [[UITableView  alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [self.view addSubview:_tableView];
    [_tableView release];
    
    // cell重用池
    [_tableView registerClass:[BtnJumpCell class] forCellReuseIdentifier:@"cell"];
    // 获取数据
    [self data];
    
}
- (void)data
{
    NSString *str = @"http://open.qyer.com/qyer/special/topic/special_list?client_id=qyer_ios&client_secret=cd254439208ab658ddf9&count=20&lat=38.88250892208679&lon=121.5399580135169&page=1&track_app_channel=App%2520Store&track_app_version=6.8.3&track_device_info=iPhone7%2C2&track_deviceid=0C79B4F1-2C09-4E9A-805E-05836431AB22&track_os=ios%25209.2&v=1";
    
    AFHTTPSessionManager *sessionManager = [AFHTTPSessionManager manager];
    [sessionManager GET:str parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
        
        NSLog(@"%lld",downloadProgress.totalUnitCount);
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSArray *arr = responseObject[@"data"];
        self.dataArr = [BtnJumpModel modelHanderWithArrar:arr];
        [_tableView reloadData];
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        NSLog(@"%@",error);
    }];
    
    
    
    
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    return _dataArr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    BtnJumpModel *m = _dataArr[indexPath.row];
    
    BtnJumpCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
  
   [cell.imgView sd_setImageWithURL:[NSURL URLWithString:m.photo]];
    cell.imgView.layer.cornerRadius = 10;
    cell.imgView.clipsToBounds = YES;
    return cell;
    
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    return 200;
    
}
#pragma mark - cell跳转
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    CellJumpViewController *cjVC = [[CellJumpViewController alloc] init];
    BtnJumpModel *m = _dataArr[indexPath.row];
    cjVC.str = m.title;
    cjVC.url = m.url;
    
    [self.navigationController pushViewController:cjVC animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
